using System.Linq;
using UnityEngine;
using QFramework;

namespace ProjectSurvivor
{
	public partial class Abilities : ViewController, IController
	{
		void Start()
		{
			Global.SimpleSwordUnlock.RegisterWithInitValue(unlocked =>
			{
				if (unlocked)
				{
					SimpleSword.Show();
				}
			}).UnRegisterWhenGameObjectDestroyed(gameObject);
			
			Global.SimpleKnifeUnlock.RegisterWithInitValue(unlocked =>
			{
				if (unlocked)
				{
					SimpleKnife.Show();
				}
			}).UnRegisterWhenGameObjectDestroyed(gameObject);
			
			Global.SimpleRotateSwordUnlock.RegisterWithInitValue(unlocked =>
			{
				if (unlocked)
				{
					SimpleRotateSword.Show();
				}
			}).UnRegisterWhenGameObjectDestroyed(gameObject);

			Global.SimpleBallUnlock.RegisterWithInitValue(unlocked =>
			{
				if (unlocked)
				{
					SimpleBall.Show();
				}
			}).UnRegisterWhenGameObjectDestroyed(gameObject);
			
			// 随机升级
			this.GetSystem<ExpUpgradeSystem>().Items.Where(item => item.IsWeapon)
				.ToList()
				.GetRandomItem().Upgrade();
		}

		public IArchitecture GetArchitecture()
		{
			return Global.Interface;
		}
	}
}
